<?php


namespace app\admin\model;

class compReCompProce extends Base
{
    /**
     * Desc: 部件关联类型
     * User: 苏鹏
     * Date: 2023/10/24
     * Time: 13:38
     * @return void
     */
    public function componentReProcesses(string $processes_type, $id, $is_update = 0)
    {
        //关联类型
        $processes_type = json_decode($processes_type, true);
        if(!empty($processes_type) && is_array($processes_type))
        {
            if($is_update = 1)
            {
                $this->where('component_id', $id)->delete();    //删除上一次数据，重新保存
            }

            $data = [];
            foreach($processes_type as $k=>$v)
            {
                $data[] = [
                    'component_id' => $id,
                    'processes_id' => $v,
                ];
            }
            $this->saveAll($data);
        }
    }
}